package com.warmlight.voicepacket.adapter.comm;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
import com.umeng.analytics.MobclickAgent;
import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.activity.CommTopicActivity;
import com.warmlight.voicepacket.activity.VideoDetailsActivity;
import com.warmlight.voicepacket.bean.comm.CommList;
import com.warmlight.voicepacket.plugin.QmzbMediaView;
import com.warmlight.voicepacket.ui.user.LoginRegistActivity;
import com.warmlight.voicepacket.ui.user.usercenter.LookUserCenterActivity;
import com.warmlight.voicepacket.utils.FileUtils;
import com.warmlight.voicepacket.utils.ImageLoader;
import com.warmlight.voicepacket.utils.Log;
import com.warmlight.voicepacket.utils.SPUtils;
import com.warmlight.voicepacket.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by weiweijinpeng on 2018/8/9.
 */

public class FocusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    public static final int ITEM_TYPE_RECOMM = 1;
    public static final int ITEM_TYPE_PICTURE = 2;
    public static final int ITEM_TYPE_RECOMM_NORMAL = 3;
    public static final int ITEM_TYPE_VERTICAL_VIDEO = 4;

    private Context mContext;

    private FocusItemListener focusItemListener;

    private List<CommList> commBeans;

    private CommList commList;

    private String topicContent;

    private LayoutInflater inflater;

    protected boolean isScrolling = false;

    private String itemId;

    public void setScrolling(boolean scrolling) {
        isScrolling = scrolling;
    }

    public FocusAdapter(Context context, FocusItemListener itemListener,String itemId){

        this.mContext=context;
        this.itemId=itemId;
        this.focusItemListener=itemListener;
        inflater = LayoutInflater.from(context);
        commBeans=new ArrayList<>();
    }

    public void addData(List<CommList> mData) {
        if (mData!=null){
            commBeans.addAll(mData);
            notifyDataSetChanged();
        }
    }

    public void setData(List<CommList> mData) {
        if (mData!=null){
            commBeans.clear();
            commBeans.addAll(mData);
            notifyDataSetChanged();
        }
    }

    public List<CommList> getData(){
        return commBeans;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        View view;
        switch (viewType) {
            case ITEM_TYPE_RECOMM:
                view = inflater.inflate(R.layout.item_focus_vertical, parent, false);
                viewHolder = new FocusRecommViewHolder(view);
                break;
            case ITEM_TYPE_PICTURE:
                view = inflater.inflate(R.layout.item_focus_horizontal, parent, false);
                viewHolder = new FocusPictureViewHolder(view);
                break;
            case ITEM_TYPE_RECOMM_NORMAL:
                view = inflater.inflate(R.layout.item_focus_horizontal_video, parent, false);
                viewHolder = new FocusRecommNormalViewHolder(view);
                break;
            case ITEM_TYPE_VERTICAL_VIDEO:
                view = inflater.inflate(R.layout.item_focus_vertical_video, parent, false);
                viewHolder = new FocusVerticalVideoViewHolder(view);
                break;
            default:
                throw new IllegalArgumentException("Invalid viewType");
        }
        return viewHolder;
    }

    @SuppressLint("WrongConstant")
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        if (holder instanceof FocusAdapter.FocusRecommViewHolder) {

            FocusRecommViewHolder verticalHolder=(FocusRecommViewHolder) holder;

            commList=commBeans.get(position);

            String content;

            topicContent="";

            if (commList.getTopic().size()>0)
                for (int i=0;i<commList.getTopic().size();i++){
                    topicContent = topicContent + "#"+commList.getTopic().get(i).getTitle()+"#";
//                    commList.setContent(topicContent+commList.getContent());
                }

            content=topicContent + commList.getContent();

            //评论的布局
            commViewGroup(verticalHolder,position);

            verticalHolder.mLikeView.setTag(position);

            verticalHolder.mRecommContent.setTag(position);

            verticalHolder.mCommentsView.setTag(position);

            verticalHolder.mShareView.setTag(position);

            verticalHolder.mCommRecommContent.setTag(position);

            UIUtils.loadImage(verticalHolder.mUserIcon,commList.getUser().getAvator());

            verticalHolder.mUserNickName.setText(commList.getUser().getNickname());

            verticalHolder.mRecommContent.setVisibility(TextUtils.isEmpty(content) ? View.GONE : View.VISIBLE);

            //富文本
            verticalHolder.mRecommContent.setText(setTextView(content,verticalHolder.mRecommContent,position));

            //点赞的数量
            isLike(verticalHolder.mLikeView,position);

            if (commList.getComment_num().equals("0")){
                verticalHolder.mCommentsView.setText("评论");

            }else{
                verticalHolder.mCommentsView.setText(String.valueOf(commList.getComment_num()));

            }

            if (commList.getShare_num().equals("0")){
                verticalHolder.mShareView.setText("分享");

            }else{
                verticalHolder.mShareView.setText(String.valueOf(commList.getShare_num()));
            }

            verticalHolder.mUserIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.mUserNickName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.center_video.mPlayerView.setImageResource(R.drawable.ic_video_play);

            try {

                if (commList.getVideo().getCover_img() !=null)
                    ImageLoader.smallVideoBackground(mContext, commList.getVideo().getCover_img().getU(), verticalHolder.center_video.mBackground);//加载背景图片

            }catch (Exception e) {
                e.printStackTrace();
            }

        }else if (holder instanceof FocusAdapter.FocusPictureViewHolder){
            FocusPictureViewHolder horizontalViewHolder=(FocusPictureViewHolder) holder;

            commList=commBeans.get(position);

            String content;

            topicContent="";

            if (commList.getTopic().size()>0)
                for (int i=0;i<commList.getTopic().size();i++){
                    topicContent= topicContent + "#"+commList.getTopic().get(i).getTitle()+"#";
//                    commList.setContent(topicContent+commList.getContent());
                }

            content=topicContent + commList.getContent();

            //评论的布局
            commViewGroup(horizontalViewHolder,position);

            horizontalViewHolder.mLikeView.setTag(position);

            horizontalViewHolder.mCommentsView.setTag(position);

            horizontalViewHolder.mShareView.setTag(position);

            horizontalViewHolder.mRecommContent.setTag(position);

            horizontalViewHolder.mCommRecommContent.setTag(position);

            UIUtils.loadImage(horizontalViewHolder.mUserIcon,commList.getUser().getAvator());

            horizontalViewHolder.mUserNickName.setText(commList.getUser().getNickname());

            horizontalViewHolder.mRecommContent.setVisibility(TextUtils.isEmpty(content) ? View.GONE : View.VISIBLE);

            //富文本
            horizontalViewHolder.mRecommContent.setText(setTextView(content,horizontalViewHolder.mRecommContent,position));

            isLike(horizontalViewHolder.mLikeView,position);

            if (commList.getComment_num().equals("0")){
                horizontalViewHolder.mCommentsView.setText("评论");

            }else{
                horizontalViewHolder.mCommentsView.setText(String.valueOf(commList.getComment_num()));

            }

            if (commList.getShare_num().equals("0")){
                horizontalViewHolder.mShareView.setText("分享");

            }else{
                horizontalViewHolder.mShareView.setText(String.valueOf(commList.getShare_num()));
            }

            horizontalViewHolder.mUserIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            horizontalViewHolder.mUserNickName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            ArrayList<ImageInfo> imageInfo = new ArrayList<>();
            for (int i = 0; i < commList.getPics().size(); i++) {
                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(commList.getPics().get(i).getU());
                info.setBigImageUrl(commList.getPics().get(i).getU());
                imageInfo.add(info);
            }
            horizontalViewHolder.scrollGirdView.setAdapter(new NineGridViewClickAdapter(mContext, imageInfo));

            NineGridViewClickAdapter nineGridViewClickAdapter = new NineGridViewClickAdapter(mContext, imageInfo);

            nineGridViewClickAdapter.setId(commList.getId());

            horizontalViewHolder.scrollGirdView.setAdapter(nineGridViewClickAdapter);

            if (imageInfo.size() > 0) {
                horizontalViewHolder.scrollGirdView.setVisibility(View.VISIBLE);
            } else {
                horizontalViewHolder.scrollGirdView.setVisibility(View.GONE);
            }

        }else if (holder instanceof FocusAdapter.FocusRecommNormalViewHolder){

            FocusRecommNormalViewHolder verticalHolder=(FocusRecommNormalViewHolder) holder;

            commList=commBeans.get(position);

            String content;

            topicContent="";

            if (commList.getTopic().size()>0)
                for (int i=0;i<commList.getTopic().size();i++){
                    topicContent= topicContent + "#"+commList.getTopic().get(i).getTitle()+"#";
//                    commList.setContent(topicContent+commList.getContent());
                }

            content=topicContent + commList.getContent();

            //评论的布局
            commViewGroup(verticalHolder,position);

            verticalHolder.mLikeView.setTag(position);

            verticalHolder.mCommentsView.setTag(position);

            verticalHolder.mShareView.setTag(position);

            verticalHolder.mRecommContent.setTag(position);

            verticalHolder.mCommRecommContent.setTag(position);

            UIUtils.loadImage(verticalHolder.mUserIcon,commList.getUser().getAvator());

            verticalHolder.mUserNickName.setText(commList.getUser().getNickname());

            verticalHolder.mRecommContent.setVisibility(TextUtils.isEmpty(content) ? View.GONE : View.VISIBLE);

            //富文本
            verticalHolder.mRecommContent.setText(setTextView(content,verticalHolder.mRecommContent,position));

            isLike(verticalHolder.mLikeView,position);

            if (commList.getComment_num().equals("0")){
                verticalHolder.mCommentsView.setText("评论");

            }else{
                verticalHolder.mCommentsView.setText(String.valueOf(commList.getComment_num()));

            }

            if (commList.getShare_num().equals("0")){
                verticalHolder.mShareView.setText("分享");

            }else{
                verticalHolder.mShareView.setText(String.valueOf(commList.getShare_num()));
            }

            FileUtils.showUrlBlur(verticalHolder.center_video.simpleDraweeView,commList.getVideo().getCover_img().getU(),30,30);

            verticalHolder.mUserIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.mUserNickName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.center_video.mPlayerView.setImageResource(R.drawable.ic_video_play);


            try {
                ImageLoader.smallVideoBackground(mContext, commList.getVideo().getCover_img().getU(), verticalHolder.center_video.mBackground);//加载背景图片
            }catch (Exception e) {
                e.printStackTrace();
            }

        }else if (holder instanceof FocusAdapter.FocusVerticalVideoViewHolder){

        }
    }


    public void videoPreppare(View view,int currentPosition){
        //快速上下滑动时，view有可能找不到指定的ID，
        try {
            if (commBeans.size()>currentPosition)
                commList=commBeans.get(currentPosition);

            QmzbMediaView qmzbMediaView=view.findViewById(R.id.seek_detail_video);

            if (commList.getVideo() !=null){

                qmzbMediaView.prepareVideo(commList.getVideo().getU());

                MobclickAgent.onEvent(mContext,"pla_Feed_video_splay",commList.getId());
            }


        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private CharSequence setTextView(String desc, TextView tv, final int position) {
        final CommList commList=commBeans.get(position);

        /*正则表达式  取出 两个#之间的内容 （不包含#） */
        Pattern p = Pattern.compile("#([^\\#|]+)#");
        /*android 提供的 具有强大的CharSequence 处理能力 各种区域处理*/
        SpannableString ss = new SpannableString(desc);
        Matcher m = p.matcher(desc);
        /*由于@昵称、#话题#、http://等这些关键字是可以点击的，所以我们需要对TextView做一些处理，需要去设置它的MovementMethod*/
        if (m.find()) {
            // 要实现文字的点击效果，这里需要做特殊处理
            tv.setMovementMethod(LinkMovementMethod.getInstance());
            // 重置正则位置
            m.reset();
        }
        /*循环找出每个复合正则的字符串，逐个处理*/
        while (m.find()) {
            /*取出 字符串 前后添加#*/
            final String s = "#" + m.group(1) + "#";
            int startIndex = m.start(1) - 1;
            int endIndex = startIndex + s.length();
            /*区域处理*/
            ss.setSpan(new ForegroundColorSpan(Color.BLUE),startIndex,endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ss.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View widget) {
                    //去掉两边的#号，获取点击的话题内容
                    String content=s.substring(1,s.length()-1);
                    String topicId="";//话题的id
                    for (int i=0;i<commList.getTopic().size();i++){
                        if (content.equals(commList.getTopic().get(i).getTitle())){
                            topicId=commList.getTopic().get(i).getId();
                        }
                    }
                    if (topicId.equals(itemId)){
                        return;
                    }
                    CommTopicActivity.startCommTopicActivity(mContext,topicId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_topic",commList.getId()+"_"+topicId);
                }
                @Override
                public void updateDrawState(TextPaint ds) {
                    //        super.updateDrawState(ds);
                    //    按自己需求    重写 父类方法.
                    //        字体变色
                    ds.setColor(Color.parseColor("#507daf"));
                    //            设置下划线
                    ds.setUnderlineText(false);
                }
            }, startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        return ss;
    }

    /**
     * 帖子的点赞状态
     * @param verticalHolder
     */
    public void isLike(TextView verticalHolder,int position){
        CommList commList=commBeans.get(position);
        Log.e("点赞状态"+commList.getIs_like());

        Drawable nav_up;
        if (commList.getIs_like()==1){
            nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_true);
            nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
            verticalHolder.setCompoundDrawables(nav_up, null, null, null);

        }else if (commList.getIs_like()==0){
            nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_false);
            nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
            verticalHolder.setCompoundDrawables(nav_up, null, null, null);
        }

        if (commList.getLike_num().equals("0")){
            verticalHolder.setText("点赞");

        }else{
            verticalHolder.setText(commList.getLike_num());
        }
    }

    public void isLike(int position){
        notifyDataSetChanged();
    }

    /**
     * 评论的布局
     */
    @SuppressLint("WrongConstant")
    private void commViewGroup(FocusRecommViewHolder verticalHolder, final int position){
        commList=commBeans.get(position);

        if (commList.getGod_info()!=null){

            verticalHolder.mCommView.setVisibility(View.VISIBLE);

            verticalHolder.mCommLayout.setVisibility(View.VISIBLE);

            UIUtils.loadImage(verticalHolder.mCommUserIcon,commList.getGod_info().getUser().getAvator());

            verticalHolder.mCommUserNickName.setText(commList.getGod_info().getUser().getNickname());

            verticalHolder.mCommRecommContent.setVisibility(TextUtils.isEmpty(commList.getGod_info().getContent()) ? View.GONE : View.VISIBLE);

            verticalHolder.mCommRecommContent.setText(commList.getGod_info().getContent());

            verticalHolder.mCommViewLike.setText(commList.getGod_info().getLike_num());

            verticalHolder.mCommViewLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    focusItemListener.isLikeCommClick(position,"video","comm");
                }
            });

            verticalHolder.mCommUserIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getGod_info().getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.mCommUserNickName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getGod_info().getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            Drawable nav_up;
            if (commList.getGod_info().getIs_like()==1){
                nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_true);
                nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                verticalHolder.mCommViewLike.setCompoundDrawables(nav_up, null, null, null);

            }else if (commList.getGod_info().getIs_like()==0){
                nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_false);
                nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                verticalHolder.mCommViewLike.setCompoundDrawables(nav_up, null, null, null);
            }

            final List<String> array=new ArrayList<>();

            final List<Boolean> gif_array=new ArrayList<>();

            final List<ImageInfo> imageInfo = new ArrayList<>();

            for (int i = 0; i < commList.getGod_info().getPics().size(); i++) {
                array.add(commList.getGod_info().getPics().get(i).getU());
                gif_array.add(commList.getGod_info().getPics().get(i).isIs_gif());

                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(commList.getGod_info().getPics().get(i).getU());
                info.setBigImageUrl(commList.getGod_info().getPics().get(i).getU());
                imageInfo.add(info);
            }

            if (imageInfo.size()>0){
                verticalHolder.comm_scrollGirdView.setVisibility(View.VISIBLE);
                NineGridViewClickAdapter nineGridViewClickAdapter = new NineGridViewClickAdapter(mContext, imageInfo);
                nineGridViewClickAdapter.setId(commList.getId());
                verticalHolder.comm_scrollGirdView.setAdapter(nineGridViewClickAdapter);
            }else{
                verticalHolder.comm_scrollGirdView.setVisibility(View.GONE);
            }

        }else{
            verticalHolder.mCommView.setVisibility(View.GONE);
            verticalHolder.mCommLayout.setVisibility(View.GONE);
        }

    }


    /**
     * 评论的布局
     */
    @SuppressLint("WrongConstant")
    private void commViewGroup(FocusPictureViewHolder verticalHolder, final int position){
        commList=commBeans.get(position);

        if (commList.getGod_info()!=null){
            verticalHolder.mCommView.setVisibility(View.VISIBLE);
            verticalHolder.mCommLayout.setVisibility(View.VISIBLE);

            UIUtils.loadImage(verticalHolder.mCommUserIcon,commList.getGod_info().getUser().getAvator());

            verticalHolder.mCommUserNickName.setText(commList.getGod_info().getUser().getNickname());

            verticalHolder.mCommRecommContent.setVisibility(TextUtils.isEmpty(commList.getGod_info().getContent()) ? View.GONE : View.VISIBLE);

            verticalHolder.mCommRecommContent.setText(commList.getGod_info().getContent());

            verticalHolder.mCommViewLike.setText(commList.getGod_info().getLike_num());

            verticalHolder.mCommViewLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    focusItemListener.isLikeCommClick(position,"picture","comm");
                }
            });

            verticalHolder.mCommUserIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getGod_info().getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.mCommUserNickName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getGod_info().getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            Drawable nav_up;
            if (commList.getGod_info().getIs_like()==1){
                nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_true);
                nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                verticalHolder.mCommViewLike.setCompoundDrawables(nav_up, null, null, null);

            }else if (commList.getGod_info().getIs_like()==0){
                nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_false);
                nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                verticalHolder.mCommViewLike.setCompoundDrawables(nav_up, null, null, null);
            }

            final List<String> array=new ArrayList<>();

            final List<Boolean> gif_array=new ArrayList<>();

            final List<ImageInfo> imageInfo = new ArrayList<>();

            for (int i = 0; i < commList.getGod_info().getPics().size(); i++) {
                array.add(commList.getGod_info().getPics().get(i).getU());
                gif_array.add(commList.getGod_info().getPics().get(i).isIs_gif());

                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(commList.getGod_info().getPics().get(i).getU());
                info.setBigImageUrl(commList.getGod_info().getPics().get(i).getU());
                imageInfo.add(info);
            }

            if (imageInfo.size()>0){
                verticalHolder.comm_scrollGirdView.setVisibility(View.VISIBLE);
                NineGridViewClickAdapter nineGridViewClickAdapter = new NineGridViewClickAdapter(mContext, imageInfo);
                nineGridViewClickAdapter.setId(commList.getId());
                verticalHolder.comm_scrollGirdView.setAdapter(nineGridViewClickAdapter);
            }else{
                verticalHolder.comm_scrollGirdView.setVisibility(View.GONE);
            }

        }else{
            verticalHolder.mCommView.setVisibility(View.GONE);
            verticalHolder.mCommLayout.setVisibility(View.GONE);
        }

    }


    /**
     * 评论的布局
     */
    @SuppressLint("WrongConstant")
    private void commViewGroup(FocusRecommNormalViewHolder verticalHolder, final int position){
        commList=commBeans.get(position);

        if (commList.getGod_info()!=null){
            verticalHolder.mCommView.setVisibility(View.VISIBLE);

            verticalHolder.mCommLayout.setVisibility(View.VISIBLE);

            UIUtils.loadImage(verticalHolder.mCommUserIcon,commList.getGod_info().getUser().getAvator());

            verticalHolder.mCommUserNickName.setText(commList.getGod_info().getUser().getNickname());

            verticalHolder.mCommRecommContent.setVisibility(TextUtils.isEmpty(commList.getGod_info().getContent()) ? View.GONE :  View.VISIBLE);

            verticalHolder.mCommRecommContent.setText(commList.getGod_info().getContent());

            verticalHolder.mCommViewLike.setText(commList.getGod_info().getLike_num());

            verticalHolder.mCommViewLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    focusItemListener.isLikeCommClick(position,"videoNormal","comm");
                }
            });
//
            verticalHolder.mCommUserIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getGod_info().getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            verticalHolder.mCommUserNickName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LookUserCenterActivity.class);
                    intent.putExtra("uid",commBeans.get(position).getGod_info().getUser().getUid());
                    intent.putExtra("type","video");
                    mContext.startActivity(intent);
                }
            });

            Drawable nav_up;
            if (commList.getGod_info().getIs_like()==1){
                nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_true);
                nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                verticalHolder.mCommViewLike.setCompoundDrawables(nav_up, null, null, null);

            }else if (commList.getGod_info().getIs_like()==0){
                nav_up = mContext.getResources().getDrawable(R.drawable.icon_community_zan_false);
                nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                verticalHolder.mCommViewLike.setCompoundDrawables(nav_up, null, null, null);
            }

            final List<String> array=new ArrayList<>();

            final List<Boolean> gif_array=new ArrayList<>();

            final List<ImageInfo> imageInfo = new ArrayList<>();

            for (int i = 0; i < commList.getGod_info().getPics().size(); i++) {
                array.add(commList.getGod_info().getPics().get(i).getU());
                gif_array.add(commList.getGod_info().getPics().get(i).isIs_gif());

                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(commList.getGod_info().getPics().get(i).getU());
                info.setBigImageUrl(commList.getGod_info().getPics().get(i).getU());
                imageInfo.add(info);
            }
            if (imageInfo.size()>0){
                verticalHolder.comm_scrollGirdView.setVisibility(View.VISIBLE);
                NineGridViewClickAdapter nineGridViewClickAdapter = new NineGridViewClickAdapter(mContext, imageInfo);
                nineGridViewClickAdapter.setId(commList.getId());
                verticalHolder.comm_scrollGirdView.setAdapter(nineGridViewClickAdapter);
            }else{
                verticalHolder.comm_scrollGirdView.setVisibility(View.GONE);
            }

        }else{
            verticalHolder.mCommView.setVisibility(View.GONE);
            verticalHolder.mCommLayout.setVisibility(View.GONE);
        }

    }

    @Override
    public int getItemCount() {
        return commBeans.size();
    }

    @Override
    public int getItemViewType(int position) {

        if (commBeans.get(position).getPics().size()>0 || commBeans.get(position).getVideo()== null){
            return ITEM_TYPE_PICTURE;
        }else if (commBeans.get(position).getVideo() != null
                && commBeans.get(position).getVideo().getH() > commBeans.get(position).getVideo().getW()){
            return ITEM_TYPE_RECOMM_NORMAL;
        }
        return ITEM_TYPE_RECOMM;
    }

    public class FocusRecommViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        @BindView(R.id.user_icon)
        SimpleDraweeView mUserIcon;

        @BindView(R.id.comm_user_icon)
        SimpleDraweeView mCommUserIcon;

        @BindView(R.id.comm_gridView_picarr)
        NineGridView comm_scrollGirdView;

        @BindView(R.id.seek_detail_video)
        public QmzbMediaView center_video;

        @BindView(R.id.recomm_commlayout)
        LinearLayout mCommLayout;

        @BindView(R.id.recomm_nickname)
        TextView mUserNickName;

        @BindView(R.id.comm_recomm_nickname)
        TextView mCommUserNickName;

        @BindView(R.id.recomm_comm_like)
        public TextView mCommViewLike;

        @BindView(R.id.recomm_content)
        TextView mRecommContent;

        @BindView(R.id.comm_recomm_content)
        TextView mCommRecommContent;

        @BindView(R.id.comm_like)
        public TextView mLikeView;

        @BindView(R.id.comm_comments)
        TextView mCommentsView;

        @BindView(R.id.comm_share)
        TextView mShareView;

        @BindView(R.id.recomm_commview)
        ImageView mCommView;


        FocusRecommViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_HORIZONTAL,null,itemId);
                }
            });
        }

        @OnClick({R.id.comm_like,R.id.comm_comments,R.id.comm_share,R.id.seek_detail_video,R.id.recomm_content,R.id.comm_recomm_content})
        @Override
        public void onClick(View v) {

            int position= (int) v.getTag();
            switch (v.getId()){
                case R.id.comm_like:
                    if (! SPUtils.isLogined()) {
                        LoginRegistActivity.startLoginRegistActivity(mContext);
                        return;
                    }
                    focusItemListener.isLikeClick(position,"video","post");
                    MobclickAgent.onEvent(mContext,"pla_Feed_like",commBeans.get(position).getId());
                    break;
                case R.id.comm_share:
                    focusItemListener.shareClick(position);
                    MobclickAgent.onEvent(mContext,"pla_Feed_share",commBeans.get(position).getId());
                    break;
                case R.id.comm_comments:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_HORIZONTAL,"1",itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_com",commBeans.get(position).getId());
                    break;
                case R.id.recomm_content:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_HORIZONTAL,null,itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_txt",commBeans.get(position).getId());
                    break;
                case R.id.comm_recomm_content:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_HORIZONTAL,"1",itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_txt_god",commBeans.get(position).getId()+"_"+commBeans.get(position).getGod_info().getId());
                    break;
            }
        }
    }

    public class FocusPictureViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        @BindView(R.id.user_icon)
        SimpleDraweeView mUserIcon;

        @BindView(R.id.comm_user_icon)
        SimpleDraweeView mCommUserIcon;

        @BindView(R.id.gridView_picarr)
        NineGridView scrollGirdView;

        @BindView(R.id.comm_gridView_picarr)
        NineGridView comm_scrollGirdView;

        @BindView(R.id.recomm_commlayout)
        LinearLayout mCommLayout;

        @BindView(R.id.recomm_nickname)
        TextView mUserNickName;

        @BindView(R.id.comm_recomm_nickname)
        TextView mCommUserNickName;

        @BindView(R.id.recomm_content)
        TextView mRecommContent;

        @BindView(R.id.comm_recomm_content)
        TextView mCommRecommContent;

        @BindView(R.id.comm_like)
        public TextView mLikeView;

        @BindView(R.id.recomm_comm_like)
        public TextView mCommViewLike;

        @BindView(R.id.comm_comments)
        TextView mCommentsView;

        @BindView(R.id.comm_share)
        TextView mShareView;

        @BindView(R.id.recomm_commview)
        ImageView mCommView;
        FocusPictureViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_PICTURE,null,itemId);
                }
            });
        }

        @OnClick({R.id.comm_like,R.id.comm_comments,R.id.comm_share,R.id.recomm_content,R.id.comm_recomm_content})
        @Override
        public void onClick(View v) {

            int position= (int) v.getTag();

            switch (v.getId()){
                case R.id.comm_like:
                    if (! SPUtils.isLogined()) {
                        LoginRegistActivity.startLoginRegistActivity(mContext);
                        return;
                    }
                    focusItemListener.isLikeClick(position,"picture","post");
                    MobclickAgent.onEvent(mContext,"pla_Feed_like",commBeans.get(position).getId());
                    break;
                case R.id.comm_share:
                    focusItemListener.shareClick(position);
                    MobclickAgent.onEvent(mContext,"pla_Feed_share",commBeans.get(position).getId());
                    break;
                case R.id.comm_comments:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_PICTURE,"1",itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_com",commBeans.get(position).getId());
                    break;
                case R.id.recomm_content:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_PICTURE,null,itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_txt",commBeans.get(position).getId());
                    break;
                case R.id.comm_recomm_content:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_PICTURE,"1",itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_txt_god",commBeans.get(position).getId()+"_"+commBeans.get(position).getGod_info().getId());
                    break;
            }
        }
    }

    public class FocusRecommNormalViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        @BindView(R.id.user_icon)
        SimpleDraweeView mUserIcon;

        @BindView(R.id.comm_user_icon)
        SimpleDraweeView mCommUserIcon;

        @BindView(R.id.comm_gridView_picarr)
        NineGridView comm_scrollGirdView;

        @BindView(R.id.seek_detail_video)
        public QmzbMediaView center_video;

        @BindView(R.id.recomm_commlayout)
        LinearLayout mCommLayout;

        @BindView(R.id.recomm_nickname)
        TextView mUserNickName;

        @BindView(R.id.comm_recomm_nickname)
        TextView mCommUserNickName;

        @BindView(R.id.recomm_content)
        TextView mRecommContent;

        @BindView(R.id.comm_recomm_content)
        TextView mCommRecommContent;

        @BindView(R.id.comm_like)
        public TextView mLikeView;

        @BindView(R.id.recomm_comm_like)
        public TextView mCommViewLike;

        @BindView(R.id.comm_comments)
        TextView mCommentsView;

        @BindView(R.id.comm_share)
        TextView mShareView;

        @BindView(R.id.recomm_commview)
        ImageView mCommView;

        FocusRecommNormalViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_VERTICAL,null,itemId);
                }
            });
        }

        @OnClick({R.id.comm_like,R.id.comm_comments,R.id.comm_share,R.id.seek_detail_video,R.id.recomm_content,R.id.comm_recomm_content})
        @Override
        public void onClick(View v) {
            int position= (int) v.getTag();
            switch (v.getId()){
                case R.id.comm_like:
                    if (! SPUtils.isLogined()) {
                        LoginRegistActivity.startLoginRegistActivity(mContext);
                        return;
                    }
                    focusItemListener.isLikeClick(position,"videoNormal","post");
                    MobclickAgent.onEvent(mContext,"pla_Feed_like",commBeans.get(position).getId());
                    break;
                case R.id.comm_share:
                    focusItemListener.shareClick(position);
                    MobclickAgent.onEvent(mContext,"pla_Feed_share",commBeans.get(position).getId());
                    break;
                case R.id.comm_comments:
                    MobclickAgent.onEvent(mContext,"pla_Feed_com",commBeans.get(position).getId());
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_VERTICAL,"1",itemId);
                    break;
                case R.id.recomm_content:
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_VERTICAL,null,itemId);
                    MobclickAgent.onEvent(mContext,"pla_Feed_txt",commBeans.get(position).getId());
                    break;
                case R.id.comm_recomm_content:
                    MobclickAgent.onEvent(mContext,"pla_Feed_txt_god",commBeans.get(position).getId()+"_"+commBeans.get(position).getGod_info().getId());
                    VideoDetailsActivity.startVideoDetailsActivity(mContext,commBeans.get(getPosition()).getId(),VideoDetailsActivity.VIDEO_VERTICAL,"1",itemId);
                    break;
            }
        }
    }

    public class FocusVerticalVideoViewHolder extends RecyclerView.ViewHolder{

        FocusVerticalVideoViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface FocusItemListener{
        void isLikeClick(int position,String type,String typeClick);
        void isLikeCommClick(int position,String type,String typeClick);
        void shareClick(int position);
    }

}
